package TestCases;

import static org.junit.Assert.*;


import java.util.ArrayList;


import org.junit.Test;

import fxTrader.retriever.CurrencyRetriever;

import updater.currency.convertor.DateChecker;
import updater.currency.data.Currency;

public class DateCheckerTestCase {
// Unit Testing
	@Test
	public void TestCase1_isSameDate() {
		// Test Data: Completely same date and time
		boolean result = DateChecker.isSameDate(
				"Wed, 20 Mar 2013 21:54:33 GMT",
				"Wed, 20 Mar 2013 21:54:33 GMT");
		assertEquals(result, true);
	}

	@Test
	public void TestCase2_isSameDate() {
		// Test Date: Different date
		boolean result = DateChecker.isSameDate(
				"Wed, 20 Mar 2013 21:54:33 GMT",
				"Thu, 21 Mar 2013 21:54:33 GMT");
		assertEquals(result, false);
	}

	@Test
	public void TestCase3_isSameDate() {

		// Test Date: Same date but different time (hour)
		boolean result = DateChecker.isSameDate(
				"Wed, 20 Mar 2013 20:54:31 GMT",
				"Wed, 20 Mar 2013 21:54:33 GMT");
		assertEquals(result, true);
	}

	@Test
	public void TestCase4_isSameDate() {

		// Test Date: Different Month
		boolean result = DateChecker.isSameDate(
				"Wed, 20 Mar 2013 20:54:31 GMT",
				"Wed, 20 Apr 2013 20:54:31 GMT");
		assertEquals(result, false);
	}

	@Test
	public void TestCase5_isSameDate() {

		// Test Date: Same date but different time (seconds)
		boolean result = DateChecker.isSameDate(
				"Wed, 20 Mar 2013 20:54:31 GMT",
				"Wed, 20 Apr 2013 20:54:61 GMT");
		assertEquals(result, false);
	}

	@Test
	public void TestCase6_isSameDate() {

		// Test Date: invalid date string
		boolean result = DateChecker.isSameDate("Wed, 20 2 GMT",
				"Wed, 20 3:54:61 GMT");
		assertEquals(result, false);
	}

	@Test
	public void TestCase7_isSameDate() {

		// Test Date: invalid date string
		boolean result = DateChecker.isSameDate(
				"Fri, 22 Apr 2014 20:54:31 GMT",
				"Wed, 20 Apr 2013 20:54:31 GMT");
		assertEquals(result, false);
	}

	@Test
	public void TestCase1_getShortDateFromFullDate() {

		String result = DateChecker
				.getDateFromFullDate("Wed, 20 Mar 2013 20:54:31 GMT");
		assertEquals(result, "20-3-2013");
	}

	@Test
	public void TestCase2_getShortDateFromFullDate() {

		String result = DateChecker
				.getDateFromFullDate("Wed, 20 Apr 2013 20:54:31 GMT");
		assertEquals(result, "20-4-2013");
	}

	@Test
	public void TestCase3_getShortDateFromFullDate() {

		String result = DateChecker
				.getDateFromFullDate("Wed, 20 XX 2013 20:54:31 GMT");
		assertEquals(result, "Invalid date");
	}
	@Test
	public void TestCase1_isExistDateOfCurrency() {
		
		Currency currency = CurrencyRetriever.getLatestCurrencyBySymbol("JPY");
		ArrayList<Currency> currencyList = CurrencyRetriever.getCurrencyListBySymbol("JPY");
		boolean result = DateChecker
				.isExistDateOfCurrency(currency,currencyList);
		assertEquals(result, true);
	}
	@Test
	public void TestCase2_isExistDateOfCurrency() {
		
		Currency currency = CurrencyRetriever.getLatestCurrencyBySymbol("DateCheckerTestCase1");
		ArrayList<Currency> currencyList = CurrencyRetriever.getCurrencyListBySymbol("DateCheckerTestCase2");
		boolean result = DateChecker
				.isExistDateOfCurrency(currency,currencyList);
		assertEquals(result, false);
	}
	
	@Test
	public void TestCase1_isExistDateOfCurrencyAndTheLeast() {
		
		Currency currency = CurrencyRetriever.getLatestCurrencyBySymbol("JPY");
		ArrayList<Currency> currencyList = CurrencyRetriever.getCurrencyListBySymbol("JPY");
		boolean result = DateChecker
				.isExistDateOfCurrencyAndTheLeast(currency,currencyList);
		assertEquals(result, true);
	}
	
	@Test
	public void TestCase2_isExistDateOfCurrencyAndTheLeast() {
		
		Currency currency = CurrencyRetriever.getLatestCurrencyBySymbol("DateCheckerTestCase1");
		
		ArrayList<Currency> currencyList = CurrencyRetriever.getCurrencyListBySymbol("DateCheckerTestCase2");
	
		boolean result = DateChecker
				.isExistDateOfCurrencyAndTheLeast(currency,currencyList);
		assertEquals(result, false);
	}
	
	
	//
}
